################################################################################
#
# PCSX_REARMED
#
################################################################################

PCSX_REARMED_VERSION = 9d3801c90db3dee73a7a30d898857ad1a5821e59
PCSX_REARMED_SITE = git://github.com/notaz/pcsx_rearmed.git
PCSX_REARMED_DEPENDENCIES = sdl libpng zlib
PCSX_REARMED_GIT_SUBMODULES = YES

PCSX_REARMED_MAKEFILE_CONFIGURATION  = TARGET=pcsx_rearmed
PCSX_REARMED_MAKEFILE_CONFIGURATION += NO_CONFIG_MAK=yes
PCSX_REARMED_MAKEFILE_CONFIGURATION += ARCH=arm
PCSX_REARMED_MAKEFILE_CONFIGURATION += HAVE_NEON=0
PCSX_REARMED_MAKEFILE_CONFIGURATION += PLATFORM=generic
PCSX_REARMED_MAKEFILE_CONFIGURATION += BUILTIN_GPU=peops
PCSX_REARMED_MAKEFILE_CONFIGURATION += SOUND_DRIVERS=sdl
PCSX_REARMED_MAKEFILE_CONFIGURATION += PLUGIN=
PCSX_REARMED_MAKEFILE_CONFIGURATION += USE_DYNAREC=1

PCSX_REARMED_SDL_INCLUDE = -I$(STAGING_DIR)/usr/include/SDL
PCSX_REARMED_SDL_LIBRARY = -L$(STAGING_DIR)/usr/lib
PCSX_REARMED_ALL_LIBRARIES = $(PCSX_REARMED_SDL_LIBRARY) -ldl -lpthread -lSDL -lpng -lz

define PCSX_REARMED_BUILD_CMDS
	$(SED) "s|-O2|-O3|g" $(@D)/Makefile
	CFLAGS="$(TARGET_CFLAGS) $(COMPILER_COMMONS_CFLAGS_NOLTO) $(PCSX_REARMED_SDL_INCLUDE)" \
		CXXFLAGS="$(TARGET_CXXFLAGS) $(COMPILER_COMMONS_CXXFLAGS_NOLTO) $(PCSX_REARMED_SDL_INCLUDE)" \
		LDFLAGS="$(TARGET_LDFLAGS) $(COMPILER_COMMONS_LDFLAGS_NOLTO) $(PCSX_REARMED_ALL_LIBRARIES)" \
		$(MAKE) CXX="$(TARGET_CXX)" CC="$(TARGET_CC)" AR="$(TARGET_AR)" -C $(@D) -f Makefile $(PCSX_REARMED_MAKEFILE_CONFIGURATION)
endef

define PCSX_REARMED_INSTALL_TARGET_CMDS
	$(INSTALL) -D $(@D)/pcsx_rearmed \
		$(TARGET_DIR)/usr/bin/pcsx_rearmed
endef

define PCSX_REARMED_PRE_PATCH_FIXUP
	$(SED) 's/\r//g' $(@D)/libpcsxcore/plugins.c
	$(SED) 's/\r//g' $(@D)/libpcsxcore/plugins.h
endef

PCSX_REARMED_PRE_PATCH_HOOKS += PCSX_REARMED_PRE_PATCH_FIXUP

$(eval $(generic-package))
